<?php

/**
 * This is the model class for table "catalogues".
 *
 * The followings are the available columns in table 'catalogues':
 * @property string $id
 * @property integer $name
 * @property string $file_name
 * @property string $slug
 */
class Catalogue extends CActiveRecord {

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'catalogues';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name,file_name', 'required'),
            array('url', 'safe'),
            array('id, name, file_name, url,file_ext,old_name', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'name' => 'Tên catalogue',
            'file_name' => 'File Name',
            'url' => 'url',
            'file_ext' => 'file extension',
            'old_name' => 'file old name'
        );
    }

    public function search() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('name', $this->name);
        $criteria->compare('file_name', $this->file_name, true);
        $criteria->compare('old_name', $this->old_name, true);
        $criteria->compare('file_ext', $this->file_ext, true);
        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

}
